package com.local.controller.admin;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.local.model.EquipmentToMedie;
import com.local.model.LocalEquipment;
import com.local.page.LocalEquipmentPage;
import com.local.service.face.LocalEquipmentService;
import com.qianhai.common.constants.CommonContans;
import com.qianhai.common.controller.BaseController;

@RestController
@RequestMapping(value = "/admin/device", method = RequestMethod.POST)
public class LocalEquipmentController extends BaseController
{
	@Autowired
	private LocalEquipmentService localEquipmentService;
	
	@RequestMapping(value = "/queryDeviceByPage.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap queryDeviceByPage(
			@RequestBody LocalEquipmentPage<LocalEquipment> page)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			localEquipmentService.queryDeviceByPage(page);
			resultMap.put(CommonContans.STRUTS_DATA, page);
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
			
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	@RequestMapping(value = "/deleteByid.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap deleteByid(String id)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			localEquipmentService.deleteByPrimaryKey(id);
			
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
			
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	/**
	 * 
	 * 方法描述：切换出入口
	 * @Title: modifyEquiment 
	 * @param @param id
	 * @param @return
	 * @return ModelMap
	 * @user pichunhan
	 * 2016年5月9日
	 * @throws
	 */
	@RequestMapping(value = "/modifyEquiment.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap modifyEquiment(String id){

		ModelMap resultMap = new ModelMap();
		
		try
		{
			localEquipmentService.modifyEquiment(id);
			
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
			
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	
	}
	
	/**
	 * 
	 * 方法描述： 批量删除
	 * 
	 * @Title: deleteBatchById
	 * @param @param ids
	 * @param @return
	 * @return ModelMap
	 * @user lyf 2015年10月26日
	 * @throws
	 */
	@RequestMapping(value = "/deleteBatchById.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap deleteBatchById(@RequestBody List<String> ids)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			localEquipmentService.deleteBatchById(ids);
			
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
			
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	/**
	 * 
	 * 方法描述：绑定岗亭
	 * 
	 * @Title: addSentryBox
	 * @param @param localStation
	 * @param @return
	 * @return ModelMap
	 * @user Administrator 2015年4月7日
	 * @throws
	 */
	@RequestMapping(value = "/bindSentryBox.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap bindSentryBox(@RequestBody LocalEquipment localEquipment)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			localEquipmentService.updateByPrimaryKeySelective(localEquipment);
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	/**
	 * 
	 * 方法描述： 通过设备ID获取流媒体信息
	 * 
	 * @Title: getMedieInfoByEquimentId
	 * @param @param equmentId
	 * @param @return
	 * @return ModelMap
	 * @user lyf 2015年10月27日
	 * @throws
	 */
	@RequestMapping(value = "/getMedieInfoByEquimentId.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap getMedieInfoByEquimentId(String uuid)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			EquipmentToMedie mediaInfo = localEquipmentService
					.getMedieInfoByEquimentId(uuid);
			
			resultMap.put(CommonContans.STRUTS_DATA, mediaInfo);
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
			
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	/**
	 * 
	 * 方法描述： 修改媒体信息
	 * 
	 * @Title: modifyMedieInfo
	 * @param @param medieMapInfo
	 * @param @return
	 * @return ModelMap
	 * @user lyf 2015年10月27日
	 * @throws
	 */
	@RequestMapping(value = "/modifyMedieInfo.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap modifyMedieInfo(@RequestBody EquipmentToMedie medieMapInfo)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			localEquipmentService.modifyMedieInfo(medieMapInfo);
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	/**
	 * 
	 * 方法描述： 相机连接
	 * 
	 * @Title: connectionMedie
	 * @param @param equimentIds
	 * @param @return
	 * @return ModelMap
	 * @user lyf 2015年10月27日
	 * @throws
	 */
	@RequestMapping(value = "/connectionMedie.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap connectionMedie(@RequestBody List<String> equimentIds)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			localEquipmentService.connectionMedie(equimentIds);
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	/**
	 * 
	 * 方法描述： 断开连接
	 * 
	 * @Title: disconnectMedie
	 * @param @param equimentIds
	 * @param @return
	 * @return ModelMap
	 * @user lyf 2015年10月27日
	 * @throws
	 */
	@RequestMapping(value = "/disconnectMedie.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap disconnectMedie(@RequestBody List<String> equimentIds)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			localEquipmentService.disconnectMedie(equimentIds);
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
}
